home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / PRIMITIV / SPHR / SPHRFAC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  3.2 KB  |  133 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: SphrFac.cpp 1.1 1996/07/19 00:09:36 Damien Exp $ */
  3.  
  4. #ifndef __SPHRFAC__
  5. #include "SPHRFac.h"
  6. #endif
  7.  
  8. #ifndef __COMSPHR__
  9. #include "COMSPHR.h"
  10. #endif
  11.  
  12. #ifndef __SPHRDLL__
  13. #include "SPHRDLL.h"
  14. #endif
  15.  
  16.  
  17.  
  18. // ***** ClassFactory *****
  19.   
  20. SphereClassFactory::SphereClassFactory() {
  21.   m_cRef=0L;  // just created so no reference used
  22.   return;
  23.   }
  24.  
  25.  
  26. SphereClassFactory::~SphereClassFactory() {
  27.   return;
  28.   }
  29.  
  30. // IUnknown methods of SphereClassFactory                                                
  31. STDMETHODIMP SphereClassFactory::QueryInterface(REFIID riid, LPVOID FAR* ppv) {
  32.   *ppv=NULL;
  33.  
  34.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  35.     *ppv=(LPVOID)this;
  36.  
  37.   if (*ppv!=NULL) {
  38.     ((LPUNKNOWN)*ppv)->AddRef(); // Add reference if we give a pointer
  39.     return NOERROR;
  40.     }
  41.   else {
  42.     return ResultFromScode(E_NOINTERFACE);
  43.     }
  44.   }
  45.  
  46.  
  47. STDMETHODIMP_(ULONG) SphereClassFactory::AddRef() {
  48.   return ++m_cRef;
  49.   }
  50.  
  51.  
  52. STDMETHODIMP_(ULONG) SphereClassFactory::Release() {
  53.   ULONG   UnreleaseRef;
  54.  
  55.   UnreleaseRef=--m_cRef;
  56.  
  57.   if (m_cRef == 0)
  58.     delete this; // No reference left, so delete the SphereClassFactory
  59.  
  60.   return UnreleaseRef;
  61.   }
  62.  
  63. /*
  64.  * SphereClassFactory::CreateInstance
  65.  *
  66.  * Parameters:
  67.  *  pUnkOuter       LPUNKNOWN to the controlling IUnknown if we are
  68.  *                  being used in an aggregation.
  69.  *  riid            REFIID identifying the interface the caller
  70.  *                  desires to have for the new object.
  71.  *  ppvObj          LPVOID FAR* in which to store the desired
  72.  *                  interface pointer for the new object.
  73.  *
  74.  * Return Value:
  75.  *  HRESULT         NOERROR if successful, otherwise E_NOINTERFACE
  76.  *                  if we cannot support the requested interface.
  77.  */
  78.  
  79. STDMETHODIMP SphereClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppvObj) {
  80.   Sphere*      pObj = NULL;
  81.   HRESULT       hr;
  82.  
  83.   *ppvObj = NULL;
  84.   hr = ResultFromScode(E_OUTOFMEMORY);
  85.  
  86.   //Verify that a controlling unknown asks for IUnknown
  87.   if (pUnkOuter && !IsEqualIID(riid, IID_IUnknown))
  88.     return ResultFromScode(E_NOINTERFACE);
  89.  
  90.   //Create the object passing function to notify on destruction.
  91.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_I3DExGeometricPrimitive))
  92.     pObj = new Sphere;
  93.   else
  94.     return ResultFromScode(E_NOINTERFACE);
  95.  
  96.   hr=pObj->QueryInterface(IID_I3DExGeometricPrimitive, ppvObj);
  97.  
  98.   //Kill the object if initial creation failed.
  99.   if (FAILED(hr))
  100.     delete pObj;
  101.   else
  102.     global_count_Obj++;
  103.  
  104.   return hr;
  105.   }
  106.  
  107.  
  108. /*
  109.  * SphereClassFactory::LockServer
  110.  *
  111.  * Purpose:
  112.  *  Increments or decrements the lock count of the DLL.  If the
  113.  *  lock count goes to zero and there are no objects, the DLL
  114.  *  is allowed to unload.  See DllCanUnloadNow in "Primdll.cpp".
  115.  *
  116.  * Parameters:
  117.  *  fLock           BOOL specifying whether to increment or
  118.  *                  decrement the lock count.
  119.  *
  120.  * Return Value:
  121.  *  HRESULT         NOERROR always.
  122.  */
  123.  
  124. STDMETHODIMP SphereClassFactory::LockServer(BOOL fLock) {
  125.   if (fLock)
  126.       global_count_Lock++;
  127.   else
  128.       global_count_Lock--;
  129.  
  130.   return NOERROR;
  131.   }
  132.  
  133.